package com.carleasoft.mps.adu.business.menu.controller;


import com.carleasoft.mps.adu.business.menu.bean.entity.AuthorityMenuEntity;
import com.carleasoft.mps.adu.business.menu.service.AuthorityMenuService;
import com.carleasoft.mps.adu.business.role.bean.vo.ListAndButtonVo;
import com.carleasoft.mps.adu.business.role.service.GrantPermsService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.user.ThreadUserContext;
import com.carleasoft.mps.core.user.UserCacheData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>Description: Role controller</p>
 * @since 2020-05-11
 * @author chenzhe
 */
@RestController
@RequestMapping("/perms")
public class AuthorityMenuController {

    @Autowired
    AuthorityMenuService authorityMenuService;
    @Autowired
    GrantPermsService grantPermsService;


    /**
     * 获取菜单和按钮树
     */
    @PostMapping("/getListAndButton")
    public R<List<ListAndButtonVo>> getListAndButton(@RequestBody AuthorityMenuEntity authorityMenuEntity){
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        return R.ok(authorityMenuService.ListAndButtonTree());
    }

    /**
     * 增加按钮或菜单
     */
    @PostMapping("/addListOrButton")
    public R addListOrButton(@RequestBody AuthorityMenuEntity authorityMenuEntity){
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        return R.ok(authorityMenuService.addListOrButton(authorityMenuEntity,user));
    }

    /**
     * 编辑按钮或菜单
     */
    @PostMapping("/editListOrButton")
    public R editListOrButton(@RequestBody AuthorityMenuEntity authorityMenuEntity){
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        return R.ok(authorityMenuService.editListOrButton(authorityMenuEntity,user));
    }

    /**
     * 删除按钮或菜单
     */
    @PostMapping("/deleteListAndButton")
    public R deleteListOrButton(@RequestBody AuthorityMenuEntity authorityMenuEntity){
        UserCacheData user = ThreadUserContext.getCurrentCacheUser();
        return R.ok(authorityMenuService.deleteListOrButton(authorityMenuEntity,user));
    }
}
